﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GemTowerDefence.Towers
{
  class Amethyst : Tower
  {
    public Amethyst(Texture2D texture, Texture2D missileTexture, Vector2 position)
      : base(texture, missileTexture, position)
    {
      Damage = 15; // Set the damage
      Range = 100; // Set the range
    }

    public override void Update(GameTime gameTime)
    {
      base.Update(gameTime);

      if (MissileTimer >= 0.35f && Target != null)
      {
        var position = Vector2.Subtract(Center, new Vector2(MissileTexture.Width / 2F));
        var bullet = new Missile(MissileTexture, position, Rotation, 6, Damage);

        Missiles.Add(bullet);
        MissileTimer = 0;
      }

      for (var i = 0; i < Missiles.Count; i++)
      {
        var missile = Missiles[i];

        missile.SetRotation(Rotation);
        missile.Update(gameTime);

        if (!IsInRange(missile.Center))
          missile.Kill();

        if (HasTarget && Vector2.Distance(missile.Center, Target.Center) < 12)
        {
          Target.CurrentHealth -= missile.Damage;
          missile.Kill();
        }

        if (missile.IsDead())
        {
          Missiles.Remove(missile);
          i--;
        }
      }
    }

  }
}
